2015-09-12(胡工).sql 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. 
  2. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_OrdersPerson')
  3. BEGIN
  4. DROP VIEW [dbo].Vw_StaffPerformance_OrdersPerson
  5. END
  6. GO
  7. create View Vw_StaffPerformance_OrdersPerson
  8. as
  9. SELECT
  10. ID
  11. ,Pay_OrdNumber as 订单号
  12. ,Pay_ShootingName as 拍摄阶段
  13. ,Pay_Category as 收款类别
  14. ,Pay_TwoPinsCategory as 二销类别编号
  15. ,dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS 二销类别名称
  16. ,Pay_AmountOf as 收款金额
  17. ,Pay_OpenSingle as 接单人编号
  18. , dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人名称
  19. ,Pay_ThePayee as 收款人编号
  20. ,dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS 收款人名称
  21. ,Pay_PaymentMethod as 付款方式编号
  22. ,dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS 付款方式名称
  23. ,Pay_OrdersLocation as 接单地点
  24. ,Pay_ReceivableProject as 收款项目
  25. ,Pay_FinancialAudit as 审核状态
  26. ,Pay_FinancialAuditdPeople as 审核人
  27. ,Pay_Remark as 备注
  28. ,Pay_CreateDatetime as 收款时间
  29. ,Pay_Type as 收款类型
  30. ,(case Pay_Type
  31. when 0 then (select Cus_Name from tempTB_AggregationCustomer where Pay_OrdNumber=GP_OrderNumber)
  32. when 1 then (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  33. when 2 then (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) else '' end) as '客户名称'
  34. ,(case Pay_Type
  35. when 0 then (select Ord_PhotographyCategory from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '套系类别'
  36. ,(case Pay_Type
  37. when 0 then (select Ord_SeriesName from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '套系名称'
  38. ,(case Pay_Type
  39. when 0 then (select Ord_OrderClass from tb_ErpOrder where Pay_OrdNumber=Ord_Number)else '' end) as '订单类别'
  40. ,(case Pay_Type
  41. when 0 then (select Ord_SeriesPrice from tb_ErpOrder where Pay_OrdNumber=Ord_Number)
  42. when 1 then (select Tsorder_Money from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number)
  43. when 2 then (select Dsro_Amount from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) end) as '应收金额'
  44. ,(case Pay_Type
  45. when 0 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  46. when 1 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory))
  47. when 2 then Pay_ReceivableProject end) as '项目名称'
  48. ,case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') end as '主门市比重'
  49. ,case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') end as '副门市比重'
  50. , ( case LEFT(Pay_OpenSingle,charindex(',',Pay_OpenSingle,1))
  51. when '' then Pay_OpenSingle
  52. else LEFT(Pay_OpenSingle,charindex(',',Pay_OpenSingle,1)-1) end)as '主门市'
  53. ,len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))) as '副门市个数'
  54. --, ( case Pay_Category
  55. -- when '后期收款' then ( len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  56. -- else (select count(*) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_Type='1') end) as '副门市个数'
  57. ,(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  58. when 0 then Pay_AmountOf
  59. else cast(Pay_AmountOf * case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') end*0.01 as numeric(9,2))
  60. end) as '主门市金额'
  61. ,(case (len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',','')))))
  62. when 0 then 0
  63. else cast(Pay_AmountOf * case when (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') is null then '0' else (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') end*0.01/(len(rtrim(ltrim(Pay_OpenSingle))) - len(rtrim(ltrim(replace(Pay_OpenSingle,',',''))))) as numeric(9,2))
  64. end) as '副门市金额'
  65. ,(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) as 副订单号
  66. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  67. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber)
  68. when 1 then (select Ordpg_PhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) )
  69. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber)
  70. else '' end) as 最后拍摄时间
  71. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  72. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  73. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  74. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  75. else '' end) as 未拍个数
  76. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  77. when 0 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  78. when 1 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber))
  79. when 2 then (select Ordv_FilmSelectionStatus from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  80. else '' end) as 选片状态
  81. ,(case (select Ord_Type from tb_ErpOrder where Ord_Number=Pay_OrdNumber)
  82. when 0 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  83. when 1 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_ViceNumber=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber))
  84. when 2 then (select Ordv_FilmSelectionTime from tb_ErpOrderDigital where Ordv_Number=Pay_OrdNumber)
  85. else '' end) as 选片时间
  86. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=(select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  87. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = (select top 1 Ordpg_ViceNumber from tb_ErpOrdersPhotography where Ordpg_Number=Pay_OrdNumber) and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  88. FROM tb_ErpPayment
  89. GO
  90. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_Photograph')
  91. BEGIN
  92. DROP VIEW [dbo].Vw_StaffPerformance_Photograph
  93. END
  94. GO
  95. create View Vw_StaffPerformance_Photograph
  96. as
  97. SELECT
  98. Ordv_Number as 主订单
  99. ,Ordv_ViceNumber as 副订单
  100. ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型
  101. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  102. when 0 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  103. when 1 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  104. when 2 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  105. else '' end) as 拍摄名称
  106. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  107. when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  108. when 1 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber)
  109. when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number)
  110. else '' end) as 最后拍摄时间
  111. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  112. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  113. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  114. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  115. else '' end) as 未拍个数
  116. ,(case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选' end) as 选片状态
  117. ,Ordv_FilmSelectionTime as 选片时间
  118. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  119. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  120. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  121. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  122. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  123. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADDEBFJDFFC')
  124. else '' end) as '景点一级个数'
  125. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  126. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  127. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  128. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADEGBGAFFJC')
  129. else '' end) as '景点二级个数'
  130. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  131. when 0 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  132. when 1 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_ViceNumber=Ordv_ViceNumber and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  133. when 2 then (select count(*) as [count] from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and Ordpg_SightsLevel='BEBBBCADAFBHBCHCI')
  134. else '' end) as '景点三级个数'
  135. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  136. when 0 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  137. when 1 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  138. when 2 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  139. else '' end) as 主摄影师ID
  140. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  141. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  142. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  143. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  144. else '' end) as 主摄影师名称
  145. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  146. when 0 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  147. when 1 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  148. when 2 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  149. else '' end) as 摄影助理ID
  150. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  151. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  152. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  153. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  154. else '' end) as 摄影助理名称
  155. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  156. when 0 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  157. when 1 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  158. when 2 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  159. else '' end) as 主化妆ID
  160. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  161. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  162. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  163. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  164. else '' end) as 主化妆名称
  165. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  166. when 0 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  167. when 1 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  168. when 2 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  169. else '' end) as 化妆助理ID
  170. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  171. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  172. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  173. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  174. else '' end) as 化妆助理名称
  175. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  176. when 0 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  177. when 1 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  178. when 2 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  179. else '' end) as 引导师ID
  180. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  181. when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  182. when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,''))
  183. when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,''))
  184. else '' end) as 引导师名称
  185. ,Ordv_EarlyRepairName as '初修师ID'
  186. ,dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as '初修师'
  187. ,Ordv_RefinementName as '精修师ID'
  188. ,dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName) as '精修师'
  189. ,Ordv_DesignerName as '设计师ID'
  190. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as '设计师'
  191. ,Vw_StaffPerformance_OrdersPerson.ID
  192. ,订单号
  193. ,拍摄阶段
  194. ,收款类别
  195. ,二销类别编号
  196. ,二销类别名称
  197. ,收款金额
  198. ,接单人编号
  199. ,接单人名称
  200. ,收款人编号
  201. ,收款人名称
  202. ,付款方式编号
  203. ,付款方式名称
  204. ,接单地点
  205. ,收款项目
  206. ,审核状态
  207. ,审核人
  208. ,备注
  209. ,收款时间
  210. ,收款类型
  211. ,客户名称
  212. ,套系类别
  213. ,套系名称
  214. ,订单类别
  215. ,应收金额
  216. ,项目名称
  217. FROM tb_ErpOrderDigital
  218. left join Vw_StaffPerformance_OrdersPerson on Ordv_Number=订单号
  219. where 订单号 is not null
  220. GO
  221. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_GetProductListPreSaleQuantity]') and xtype in (N'FN', N'IF', N'TF'))
  222. BEGIN
  223. DROP FUNCTION [dbo].fn_GetProductListPreSaleQuantity
  224. END
  225. GO
  226. --订单商品表
  227. create function [dbo].[fn_GetProductListPreSaleQuantity](@Prod_Number varchar(800))
  228. Returns varchar(800)
  229. As
  230. Begin
  231. Declare @ProdCount int
  232. set @ProdCount = (select sum(OPlist_ProdQuantity) from tb_ErpOrderProductList where OPlist_ProdNumber = @Prod_Number and OPlist_Type = '2' )
  233. return @ProdCount
  234. End
  235. GO